local skel = fk.CreateSkill {
  name = "lb__qiujing",
}

Fk:loadTranslationTable {
  ["lb__qiujing"] = "囚境",
  [":lb__qiujing"] = "出牌阶段限一次，你可令两名角色秘密选择是否“出卖对方”，之后明示结果，若结果：<br>" ..
      "一致，选是/否者受到1点伤害/弃1张牌；<br>" ..
      "不一致，选否者各受到X点伤害（X为选是者数）。",

  ["@@lb__qiujing"] = "囚境",
  ["@lb__qiujing"] = "囚境",
  ["#lb__qiujing"] = "囚境：是否“出卖对方”",
  ["#lb__qiujing-ask"] = "囚境：你可以令2~%arg名角色秘密选择是否“出卖对方”",
  ["#lb__qiujing-ask2"] = "囚境：你可以令两名角色秘密选择是否“出卖对方”",

  ["$lb__qiujing1"] = "让我们尽情向彼此展现自己的价值吧。",
  ["$lb__qiujing2"] = "一枚不知价值的筹码，一张不知花色的底牌。",
}

skel:addEffect("active", {
  prompt = function(self, player, selected_cards, selected_targets)
    local n = player:getMark("@lb__qiujing")
    if n == 0 then
      return "#lb__qiujing-ask2"
    end
    return "#lb__qiujing-ask:::" .. (2 + n)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.phase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected < (player:getMark("@lb__qiujing") + 2)
  end,
  feasible = function(self, player, selected, selected_cards, card)
    return #selected > 1 and #selected <= (player:getMark("@lb__qiujing") + 2)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local ret = room:askToJointChoice(player, {
      players = effect.tos,
      choices = { "yes", "no" },
      skill_name = "lb__qiujing",
      prompt = "#lb__qiujing",
      send_log = true
    })
    local yes = table.filter(effect.tos, function(id)
      return ret[id] == "yes"
    end)
    local no = table.filter(effect.tos, function(id)
      return ret[id] == "no"
    end)
    -----
    local list = room:getTag("lb__zhangyan") or {}
    if list then
      local cai = list.choice
      if ((#yes > #no) and (cai == "yes")) or ((#yes < #no) and (cai == "no")) then
        player:drawCards(list.n, "lb__zhangyan")
        room:addPlayerMark(player, "@lb__qiujing", 1)
      else
        room:setPlayerMark(player, "@lb__qiujing", 0)
        room:setPlayerMark(player, "@@lb__qiujing", 1)
      end
      room:removeTag("lb__zhangyan")
    end
    -----
    if #no == #effect.tos or #yes == #effect.tos then
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(effect.tos, p) and not p.dead then
          if ret[p] == "yes" then
            room:damage {
              from = player,
              to = p,
              damage = 1,
              skillName = skel.name,
            }
          elseif not p:isNude() then
            room:askToDiscard(p, {
              min_num = 1,
              max_num = 1,
              include_equip = true,
              skill_name = skel.name,
              cancelable = false,
            })
          end
        end
      end
    else
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(no, p) and not p.dead then
          room:damage {
            from = player,
            to = p,
            damage = #yes,
            skillName = skel.name,
          }
        end
      end
    end
  end,
})

return skel
